export function getWeekDate (data, dateIndex) {
    const time = new Date()
    let month = time.getMonth() + 1
    const day = time.getDate()

    const monDay = new Date(data)
    const sunDay = new Date(data)
    const nowDay = new Date(data).getDay() || 7
    monDay.setDate(monDay.getDate() - nowDay + 1)
    sunDay.setDate(sunDay.getDate() - nowDay + 7)
    let monDayyear = monDay.getFullYear()
    const monDaymonth = monDay.getMonth() + 1
    const monDayDay = monDay.getDate()

    const sunDayyear = sunDay.getFullYear()
    const sunDaymonth = sunDay.getMonth() + 1
    const sunDayDay = sunDay.getDate()
    let monMonthD = monDaymonth > 9 ? monDaymonth : '0' + monDaymonth
    const monDayD = monDayDay > 9 ? monDayDay : '0' + monDayDay
    const sunMonthD = sunDaymonth > 9 ? sunDaymonth : '0' + sunDaymonth
    const sunDayD = sunDayDay > 9 ? sunDayDay : '0' + sunDayDay

    // 今天的年月日
    const nowYear = time.getFullYear()
    let nowMonth = time.getMonth() + 1
    nowMonth = nowMonth > 9 ? nowMonth : `0${nowMonth}`
    let currDay = time.getDate()
    currDay = currDay > 9 ? currDay : `0${currDay}`
    if (dateIndex === 0) {
        let weekend = false
        // this.selectDate = month + '月' + day + '日'
        // this.selectDay = time.getFullYear() + '-' + month + '-' + day
        if (new Date().getDay() === 6 || new Date().getDay() === 0) {
            weekend = true
        } else {
            weekend = false
        }
        const ParamsDates = {
            weekend: weekend,
            selectDate: month + '月' + day + '日',
            selectDay: time.getFullYear() + '-' + changeDate(month) + '-' + changeDate(day),
            startTime: `${nowYear}-${nowMonth}-${currDay}`,
            endTime: `${nowYear}-${nowMonth}-${currDay}`
        }
        return ParamsDates
    } else if (dateIndex === 2) {
        if (month > 1) {
            month = month - 1
        } else {
            month = 12
        }
        // this.selectDate = month + '月'
        if (monMonthD > 1) {
            monMonthD = monMonthD - 1
        } else {
            monMonthD = 12
            monDayyear = monDayyear - 1
        }
        // this.selectDay = monDayyear + '-' + monMonthD + '-' + monDayD
        const ParamsDates = {
            selectDate: month + '月',
            selectDay: monDayyear + '-' + monMonthD + '-' + monDayD,
            startTime: formateDateStart(),
            endTime: formateDateEnd()
        }
        return ParamsDates
    } else {
        let selectDate = ''
        if (monDayyear !== sunDayyear) {
            // 年份不同，跨年的周
            selectDate =
                monDayyear +
                '年' +
                monDaymonth +
                '月' +
                monDayDay +
                '日~' +
                sunDayyear +
                '年' +
                sunDaymonth +
                '月' +
                sunDayDay +
                '日'
        } else {
            if (monDaymonth !== sunDaymonth) {
                // 月份不同，跨月份的周
                selectDate =
                    monDaymonth +
                    '月' +
                    monDayDay +
                    '日~' +
                    sunDaymonth +
                    '月' +
                    sunDayDay +
                    '日'
            } else {
                selectDate =
                    monDaymonth + '月' + monDayDay + '日~' + sunDayDay + '日'
            }
        }
        const ParamsDates = {
            selectDate: selectDate,
            selectDay: monDayyear + '-' + monMonthD + '-' + monDayD,
            startTime: monDayyear + '-' + monMonthD + '-' + monDayD,
            endTime: sunDayyear + '-' + sunMonthD + '-' + sunDayD
        }
        // this.selectDay = monDayyear + '-' + monMonthD + '-' + monDayD
        // this.startTime = monDayyear + '-' + monMonthD + '-' + monDayD
        // this.endTime = sunDayyear + '-' + sunMonthD + '-' + sunDayD
        return ParamsDates
    }
}
// 获取月初日期
function formateDateStart () {
    const time = new Date()
    let year = time.getFullYear()
    let month = time.getMonth() + 1
    if (month > 1) {
        month = month - 1
    } else {
        month = 12
        year = year - 1
    }
    let startTime
    if (month < 10) {
        startTime = year + '-0' + month + '-' + '01'
    } else {
        startTime = year + '-' + month + '-' + '01'
    }
    return startTime
}
// 获取月末日期
function formateDateEnd () {
    const time = new Date()
    let year = time.getFullYear()
    let month = time.getMonth() + 1
    let endTime

    if (month > 1) {
        month = month - 1
    } else {
        month = 12
        year = year - 1
    }
    if (month === 2) {
        if (year % 4 === 0 || year % 100 === 0) {
            endTime = year + '-0' + month + '-29'
        } else {
            endTime = year + '-0' + month + '-28'
        }
    } else if (month === 4 || month === 6 || month === 9 || month === 11) {
        if (month < 10) {
            endTime = year + '-0' + month + '-30'
        } else {
            endTime = year + '-' + month + '-30'
        }
    } else {
        if (month < 10) {
            endTime = year + '-0' + month + '-31'
        } else {
            endTime = year + '-' + month + '-31'
        }
    }
    return endTime
}
function changeDate (number) {
    if (number < 10) {
        number = '0' + number
    }
    return number
}
